package com.zx.AnimationThread;

import java.util.ArrayList;

import android.content.res.Resources;
import android.util.Log;

public class PetalThread extends Thread{
	
	boolean flag;
	int sleepSpan = 15;
	double time = 0;
//	double span = 0.15;
	double span = 1;
	PetalView pv;
	Resources res;
	
	public PetalThread(PetalView pv,Resources res) {
		this.pv = pv;
		this.flag = true;
		this.res = res;
		Log.i("4", "res = " + res.toString());
	}
	
	public void run() {
		while(flag) {
			
			if(time % 3 == 0)
			pv.ps.add(1, time, res);
			
			ArrayList<Petal> tempSet = pv.ps.petalSet;
			int count = tempSet.size();
			
			for(int i = 0; i < tempSet.size(); i ++) {
				Petal petal = tempSet.get(i);
				double timeSpan = (time - petal.startTime)/2;
				int tempX = (int) (petal.startX + petal.horizontal_v * timeSpan);
				int tempY = (int) (petal.startY + petal.vertical_v * timeSpan);
				if(tempY > PetalView.DIE_OUT_LINE){
					tempSet.remove(i);
					count = tempSet.size();
				}
				petal.x = tempX;
				petal.y = tempY;
			}
			
			time += span;
			
			try {
				Thread.sleep(sleepSpan);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
		
	}

}
